﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using BruteForce.UserInterface.Abstracts;
using Bruteforce.UserInterface.UIControls;

namespace BruteForce.Screens.PlayingScreen.Tutorial
{
    public delegate void OnTutorialFinishHandler(Tutorial t);

    public class Tutorial
    {
        private static List<Texture2D> PanelsTexture;
        private static Texture2D ButtonTexture;

        public static void LoadContent(ContentManager content)
        {
            PanelsTexture = new List<Texture2D>();
            for (int i = 1; i <= 19; i++)
            {
                PanelsTexture.Add(content.Load<Texture2D>("Tutorial/panel" + i));
            }
            ButtonTexture = content.Load<Texture2D>("Tutorial/next");
        }

        private int currentPanelTexture = 0;
        private Vector2 location;

        public Texture2D CurrentPanelTexture { get { return PanelsTexture[currentPanelTexture]; } }
        public event OnTutorialFinishHandler OnTutorialFinished;

        public void Draw(SpriteBatch s)
        {
            s.Draw(CurrentPanelTexture, location, Color.White);
        }

        private void NextPanel()
        {
            currentPanelTexture = (currentPanelTexture + 1) % PanelsTexture.Count;
            if (currentPanelTexture == 0 && OnTutorialFinished != null) OnTutorialFinished(this); 
        }

        public void Initialize(Vector2 locationOnScreen, AbstractPanel panel)
        {
            this.currentPanelTexture = 0;
            this.location = locationOnScreen;
            var r = new Rectangle((int)(location.X + 177), (int)(location.Y + 165), ButtonTexture.Bounds.Width, ButtonTexture.Bounds.Height);
            //var r = new Rectangle(0,0, ButtonTexture.Bounds.Width, ButtonTexture.Bounds.Height);
            
            var b = new Button(ButtonTexture, "?", r);
            //b.SetOffset(new Vector2(panel.Bounds.X, panel.Bounds.Y));
            panel.AddUIControl(b);
            b.OnClick += (() => NextPanel());
        }

    }
}
